//堆溢出
 import java.util.ArrayList;
 import java.lang.OutOfMemoryError;
 public class outofmemory{
     public static void main(String args[]){
         ArrayList<byte []>list=new ArrayList<byte []>();
    	 for(int i=0;i<1024;i++){
    		 list.add(new byte[1024*1024]);// java heap space
    	//	 System.out.println("hello");
    		 ByteBuffer.allocateDirect((1024*1024));//直接申请内存
    	 /*Exception in thread "main" java.lang.OutOfMemoryError: Java heap space
    			at Subtraction.Subtraction.main(Subtraction.java:12)*/
    		 System.gc();
    	 }
     }
 }